<template>
<view>
	<view class="header">
	    员工总数:{{list.length}}
	</view>
	<view class="content">
	    <view class="list" v-for="(item,index) in list" :key="index">
	        <view class="list_left">
	            <image v-if="item.avatar" :src="item.avatar"></image>
	        </view>
	        <view class="list_center">
	            <view class="list_center_top">
	                <text>姓名:{{item.realname}}</text>
	                <text class="color">{{item.type == 1 ? '店长' : '员工'}}</text>
	            </view>
	            <view class="list_center_bottom">电话:{{item.phone}}</view>
	        </view>
	        <view class="list_right">
	            <image class="image" @click="edit(item)"  src="/static/img/none_edit.jpg"></image>
	            <image class="image1" @click="del(item.id)"  src="/static/img/none_delete.png"></image>
	        </view>
	    </view>
	</view>
	
	<staffEdit :item="item" v-if="staffEditShow" @func="close"></staffEdit>
</view>
</template>

<script>
import request from '@/util/request.js'
import staffEdit from "@/components/staff/staffEdit.vue"
export default {
	data() {
		return {
			page:1,
			list:[],
			pageShow:true,
			staffEditShow:false,
			id:'',
			type:''
		}
	},
	components:{staffEdit},
	onLoad:function(e){
		uni.showLoading({
		    title: '加载中'  
		});
		this.getList();
	},
	methods: {
		getList:function(){
			var data = {
				'oa_id':uni.getStorageSync('oa_id'),
				'page':this.page
			}
			var that = this
			request({
				url: 'manage/user/list',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(res.data.code == 1){
						if(res.data.data.last_page <= that.page){
							that.pageShow = false
						}
						if(that.page == 1){
							that.list = res.data.data.data
						}else{
							var list = that.list
							that.list = list.concat(res.data.data.data)
						}
					}
				},
			})
		},
		onReachBottom: function(){
			if(this.pageShow){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getList();
			}
		},
		edit:function(item){
			this.item = item
			this.staffEditShow = true
		},
		close:function(data){
			this.staffEditShow = false
			if(data.type){
				uni.showLoading()
				this.getList();
			}
		},
		del:function(id){
			var data = {id:id}
			var that = this
			request({
				url: 'manage/user/delete',
				method: 'delete',
				data:data,
				success: (res) => {
					if(res.data.code == 1){
						uni.showToast({
							title: '删除成功!!',
							icon: "none", 
							position:'bottom',
						});
						uni.showLoading()
						that.getList()
				  }else{
					uni.showToast({
						title: '删除失败!!',
						icon: "none", 
						position:'bottom',
					});
				  }
				},
			})
		}
	}
}
</script>

<style>
@import url("../css/user/index.css");
</style>
